package com.shop.service.Impl;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shop.mapper.DtsFeedbackMapper;
import com.shop.pojo.DtsCoupon;
import com.shop.pojo.DtsFeedback;
import com.shop.service.DtsFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName DtsFeedbackServiceImpl
 * @Author xiao宋
 * @Date 16:19  2022/10/22
 * @Version 1.0
 * @Description TODO
 */
@Service
public class DtsFeedbackServiceImpl implements DtsFeedbackService {
    @Autowired
    DtsFeedbackMapper feedbackMapper;
    @Override
    public Map<String, Object> findByPage(Integer page, Integer limit, String sort, String order, String username, Integer id) {
        QueryWrapper<DtsFeedback> w = new QueryWrapper<>();
        IPage<DtsFeedback> iPage = new Page<>(page, limit);
        if (id != null) {
            w.eq("id", id);
        }
        if (!StringUtils.isEmpty(username)) {
            w.eq("username", username);
        }
//        排序方式
        if ("desc".equalsIgnoreCase(order)) {
            w.orderByDesc(sort);
        } else {
            w.orderByAsc(sort);
        }
        w.eq("deleted", false);
        feedbackMapper.selectPage(iPage, w);
        Map<String, Object> data = new HashMap<>();
        data.put("total", iPage.getTotal());
        data.put("items", iPage.getRecords());
        return data;
    }
}
